//
//  HJLogisticsViewController.m
//  Sneakers
//
//  Created by 胡光健 on 2017/11/8.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJLogisticsViewController.h"
#import "HJLogisticsHeader.h"
#import "HJLogisticsCell.h"
#import "HJMineModel.h"

@interface HJLogisticsViewController ()
@property(nonatomic,strong) HJQueryModel * queryModel;
@property(nonatomic,strong) NSMutableArray * imageArr;
@end

@implementation HJLogisticsViewController
-(NSMutableArray *)imageArr {
    if (!_imageArr) {
        _imageArr = [NSMutableArray array];
    }
    return _imageArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navTitle= @"物流详情";
    self.queryModel = [[HJQueryModel alloc]init];
    [self loadNetworkData];
}

-(void)configTableView {
    self.tableViewStyle = UITableViewStylePlain;
    [super configTableView];
    [self.tableView registerCellByNibName:@"HJLogisticsCell"];
}
-(void)loadNetworkData {
    [TZHttpTool post:QueryAPI params:@{@"member":self.express} success:^(NSDictionary *result) {
        self.queryModel = [HJQueryModel mj_objectWithKeyValues:result[@"data"]];
        [self.imageArr  removeAllObjects];
        NSString * imageStr;
        for (int i =0; i<self.queryModel.list.count; i++) {
            if (i==0) {
                imageStr = @"address";
            }else {
                imageStr = @"dian";
            }
            [self.imageArr addObject:imageStr];
        }
        [self.tableView reloadData];
    } failure:^(NSString *msg) {
        [self showErrorHUDWithError:msg];
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.queryModel.list.count +1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row==0) {
        HJLogisticsHeader * headerCell =(HJLogisticsHeader *)[tableView cellForRowAtIndexPath:indexPath];
        if (!headerCell) {
            headerCell = [[NSBundle mainBundle]loadNibNamed:@"HJLogisticsHeader" owner:nil options:nil].firstObject;
        }
        headerCell.selectionStyle =UITableViewCellSelectionStyleNone;
        [headerCell.image sd_setImageWithURL:[NSURL URLWithString:self.shoes_image] placeholderImage:nil];
        headerCell.code.text = [NSString stringWithFormat:@"%@码",self.shoes_size];
        headerCell.buyMoney.text = [NSString stringWithFormat:@"￥%@",self.shoes_money];
        headerCell.shoesName.text = self.shoes_name;
        if (!self.queryModel.number) {
            headerCell.courierNum.text = [NSString stringWithFormat:@"快递单号： "];
        }else {
            headerCell.courierNum.text = [NSString stringWithFormat:@"快递单号：%@",self.queryModel.number];
        }
        WeakSelf
        headerCell.copyBtnBlock = ^{
            if (weakSelf.queryModel.number.length>0) {
                UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
                pasteboard.string = weakSelf.queryModel.number;
                [weakSelf showHint:@"复制成功"];
            }
        };
        return headerCell;
    }else {
        HJLogisticsCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HJLogisticsCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        HJQueryListModel * model = self.queryModel.list[indexPath.row-1];
        cell.queryModel = model;
        cell.image.image = HJImage(self.imageArr[indexPath.row -1]);
        if (indexPath.row == self.queryModel.list.count) {
            cell.lineView.hidden =YES;
        }else {
            cell.lineView.hidden = NO;
        }
        return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row==0) {
        return 230;
    }
    return 115;
}


@end
